|
|
 |
|
|
|
|
' See which points are closer. For i = 1 To NumPts ' See if the point satisfies on_left/on_top. If CBool(X < Data(i).coord(1)) = on_left And _
CBool(Z > Data(i).coord(3)) = on_top Then
' See if this point is closer than the
' best one so far. diffx = X - Data(i).coord(1)
diffz = Z - Data(i).coord(3)
dist2 = diffx * diffx + diffz * diffz
If dist2 < best_dist2 Then
best_i = i
best_dist2 = dist2
End If
End If
Next i
NearestPoint = best_i
End Function |
|
|
|
|
|
|
|
|
Example program Surface4 uses the WeightedGrid3d class to approximate a surface with missing data values. The results are much smoother than those generated by program Surface3. Figure 14.8 shows a grid approximating a set of data randomly chosen from the values displayed in Figure 14.2. This is a much better approximation than the one shown in Figure 14.7. |
|
|
|
|
|
|
|
|
Figure 14.9 shows approximations for two other surfaces. The pictures on the left show the true surfaces from which sample data was randomly selected. The middle pictures show an approximation to the sample data using the data point nearest to each grid location. The pictures on the right show approximations using weighted averages. |
|
|
|
|
|
|
|
|
Figure 14.8
A grid approximating an incomplete data set using weighted averages. |
|
|
|
|
|